<template>
  <avue-crud
    :data="data"
    :option="option"
    v-model="obj"
    @row-save="rowSave"
    @row-update="rowUpdate"
    @on-load="onLoad"></avue-crud>
</template>

<script>
import {getFoodTypes, addFoodType, updateFoodType} from '@/api/foodType'

export default {
  name: 'index',
  data () {
    return {
      obj: {},
      data: [],
      option: {
        title: '商品类型信息',
        align: 'center',
        menuAlign: 'center',
        index: true,
        column: [
          {
            label: '类型名称',
            prop: 'name'
          }
        ]
      }
    }
  },
  methods: {
    onLoad () {
      getFoodTypes(null).then(res => {
        this.data = res.data
      }).catch(err => {
        console.log(err)
      })
    },
    rowSave (form, done, loading) {
      addFoodType(this.obj).then(res => {
        this.onLoad(this.page)
        this.$message.success(res.data.msg)
        done()
      }).catch(res => {
        this.$message.error(res)
      })
    },
    rowUpdate (row, index, done, loading) {
      updateFoodType(this.obj).then(res => {
        this.onLoad(this.page)
        this.$message.success(res.data.msg)
        done()
      }).catch(res => {
        this.$message.error(res)
      })
    },
    onSubmit () {
      console.log('submit!')
    }
  }
}
</script>

<style scoped>

</style>
